package com.johnson.news.adapter;

import java.util.ArrayList;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
    ArrayList<Fragment> fragmentList = new ArrayList<>();
    ArrayList<String> titleList = new ArrayList<>();

    public MyFragmentPagerAdapter(FragmentManager fm, int behavior) {
        super(fm, behavior);
    }

    public void setData(ArrayList<Fragment> fragmentList, ArrayList<String> titleList){
        this.fragmentList.clear();
        this.titleList.clear();
        this.fragmentList.addAll(fragmentList);
        this.titleList.addAll(titleList);
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titleList.get(position);
    }
}
